﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using MySql.Data.MySqlClient;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace TravellerApp1
{
    /// <summary>
    /// Route.xaml 的交互逻辑
    /// </summary>
    public partial class Route : Window
    {
        public Route()
        {
            InitializeComponent();
        }

        private Dictionary<string, string> CityDictionary = new();

        private void btn_query_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                String cmd1 = "select resvKey from RESERVATIONS where resvType=1 and custID='" + custid.Text + "' order by time1;";
                MySqlDataReader reader = MysqlHelper.ExecuteSqlScript(cmd1);
                CityDictionary.Clear();
                while (reader.Read()) { 
                    string resvKey = reader[0].ToString();
                    string[] sArry = resvKey.Split(':');
                    CityDictionary.Add(sArry[0], sArry[1]);
                }
                string rst = "";
                string last = "";
                foreach (KeyValuePair<string, string>kvp in CityDictionary)
                {
                    if(last == kvp.Key)
                    {
                        rst += " -> " + kvp.Value;
                    }
                    else
                    {
                        rst += "\n" + kvp.Key + " -> " + kvp.Value;
                    }

                    last = kvp.Value;
                }
                MessageBox.Show(rst, "旅行线路");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //MysqlHelper.SetDatabase("travel947");
            }
            finally
            {
                MysqlHelper.CloseCon();
            }
        }
    }
}
